<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--{include file='comm/comm_region.tpl'}-->
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file="comm/comm_multiselect.tpl"}-->

    <title>财务对账</title>
</head>

<style>
    .ui-multiselect{ width: 165px !important;}
</style>
<body>
<div class="container">

    
        <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" class="form-inline" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td height="27px">
                                    <span>
                                        订单编号：<input id="bill_code" class="form-control input-sm" type="text" style="width:140px;" value="" name="bill_code">
                                    </span>
                                    <span>配送日期：<input id="send_date" class="form-control input-sm"  name="send_date" value="<!--{$currentDate|default:''}-->" type='text' style="width:100px;" readonly ></span>
                                    <button type="button" class="btn btn-default btn-sm" onclick="orderSettlement.timeClear();">清 空</button>

                                    <span>城市：<select id="deliver_cityid" class="form-control input-sm"  name="deliver_cityid" style="width:100px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>
                                    <span>配送站：<select id="distribution_id" class="form-control input-sm"  name="distribution_id" style="width:120px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>
                                    <span>配送员：<select id="distribution_technician_id" class="form-control input-sm"  name="distribution_technician_id" style="width:120px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>
                                    <span>是否配送对账：<select id="is_reconciliation" class="form-control input-sm"  name="is_reconciliation" style="width:80px;">
                                            <option value="">请选择</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>
                                        </select>
                                    </span>
                                    <span>是否财务对账：<select id="is_receivable" class="form-control input-sm"  name="is_receivable" style="width:80px;">
                                            <option value="">请选择</option>
                                            <option value="1">是</option>
                                            <option value="0">否</option>
                                        </select>
                                    </span>
                                    <span>
                                        订单品牌：<select class="form-control input-sm" name="billPlatform">
                                            <option value="1">自营</option>
                                            <option value="all">全部</option>
                                            <option value="2">澳粒</option>
                                        </select>
                                    </span>

                                    <input type="button" value="查询" class="btn btn-primary" onclick="orderSettlement.search();" />
                                    <input type="button" value="重置" class="btn btn-warning" onclick="orderSettlement.clear();" />
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>


    <!--{include file='comm/footer.tpl'}-->

</div>


    <div id="pop" style="display:none">
        <div id="select-content">
            <div class="form-inline">
                <table>
                    <tbody id="rejectCause">
                    <tr>
                        <td>
                            <span>订单号：<input type="text" id="billCode" class="form-control input-sm"  name="bill_code" value="" style="width:177px;" readonly/></span>
                            <span>订单总额：<input type="text" id="billTotalMoney" class="form-control input-sm"  name="billTotalMoney" value="" style="width:100px;" readonly/></span>
                            <span>已付金额：<input type="text" id="billPaidAmount" class="form-control input-sm"  name="billPaidAmount" value="" style="width:100px;" readonly/></span>
                            <span>未付金额：<input type="text" id="billUnpaidAmount" class="form-control input-sm"  name="billUnpaidAmount" value="" style="width:100px;" readonly/></span>
                            <span>配送员：<input type="text" id="deliveries" class="form-control input-sm"  name="deliveries" value="" style="width:100px;" readonly/></span>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <form id="reconciliationForm" name="reconciliationForm" onsubmit="return false;">
                <input type="hidden" id="bill_no" name="bill_no" value="" />
                <table class="table table-bordered table-hover" style="margin-top: 19px;">
                    <thead>
                    <tr>
                        <th>支付方式</th>
                        <th>应付金额</th>
                        <th>已付金额</th>
                        <th>未付金额</th>
                        <th>POS流水号</th>
                        <th>POS机号</th>
                        <th>现金卡号</th>
                        <th>付款金额</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="billPay">

                    </tbody>
                </table>
                <div>
                    <select class="form-control input-sm" style="width:180px;" id="changePayment">
                        <!--{foreach from=$pay_ment_array item=payment}-->
                        <option value="<!--{$payment.id}-->" flg="<!--{$payment.type}-->"><!--{$payment.name}--></option>
                        <!--{/foreach}-->
                    </select>
                    <span>
                        <button type="button" class="btn btn-primary btn-sm" style="float:left; margin-left: 209px; margin-top: -30px;" onclick="orderSettlement.addTable();">新增</button>
                    </span>
                </div>
                <div id="addPayTable" style="display: none;">
                    <table class="table table-bordered table-hover" style="margin-top: 19px;">
                        <thead>
                        <tr>
                            <th>支付方式</th>
                            <th>应付金额</th>
                            <th>已付金额</th>
                            <th>未付金额</th>
                            <th>POS流水号</th>
                            <th>POS机号</th>
                            <th>现金卡号</th>
                            <th>付款金额</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="payTbody">

                        </tbody>
                    </table>
                </div>
                <div class="form-group" style="margin-top: 19px;">
                    <label for="bill_checking_remark" class="col-sm-2 control-label"> 对账备注：</label>
                    <div class="col-sm-10">
                        <textarea  class="form-control" id="bill_checking_remark" name="bill_checking_remark" placeholder="请输入对账备注" ></textarea>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div id="pop1" style="display:none">
        <form id="rejected_form" class="form-horizontal" onsubmit="return false;">
            <input type="hidden" id="billNo" name="bill_no" value="" />
            <div class="form-group">
                <label class="col-sm-2 control-label" for="description">
                    驳回原因：
                </label>
                <div class="col-sm-10">
                    <textarea style="height:80px;padding-left:10px;" name="bill_reject_cause" id="description" class="form-control" placeholder="请输入驳回原因"></textarea>
                </div>
            </div>
        </form>
    </div>


<script type="text/javascript" src="/inc/config/default/region.min.js"></script>
<script type="text/javascript" src="/framework/ebsig/js/region.change.min.js"></script>
<!--baidu map-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=8d5812593e46968cd655b1a6c1af9c93"></script>

<script type="text/javascript">

$('#send_date').datepicker();

var table_id = <!--{$table_id}-->;

var fixed_json = <!--{$fixed_json}-->;

$("#flex").flexigrid({
    url:"/invokingAjax-backend/send/financialReconciliation.ajax?operFlg=1",
    dataType: "json",
    colModel : fixed_json,
    <!--{if $edit_permission}-->
    buttons : [
        {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
        {separator: true},
        {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"},
        {separator: true},
        {name: "批量财务对账", bclass: "add", onpress : "orderSettlement.financialReconciliation"}
    ],
    <!--{/if}-->
    sortname: "createTime,distribution_technician_id",
    sortorder: "desc",
    usepager: true,
    rp: 30,
    useRp: true,
    showTableToggleBtn: true,
    autoload: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    },

    //拉伸宽度后触发
    onColResize:function(){

        var last_cid = arguments[0];
        var width = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=1',
            data:{
                table_id:table_id,
                last_cid:last_cid,
                width:width
            },
            call:function( o ){ }

        });

    },

    //隐藏后触发
    onToggleCol:function(){

        var cid = arguments[0];
        var hide = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=3',
            data:{
                table_id:table_id,
                cid:cid,
                hide:hide
            },
            call:function( o ){ }

        });

    },

    //拖拽后触发
    onDragCol:function(){

        var cid = arguments[0];
        var last_cid = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=2',
            data:{
                table_id:table_id,
                cid:cid,
                last_cid:last_cid
            },
            call:function( o ){ }

        });

    }

});

$('#billType').multiselect();
$('#bill_status').multiselect();

var orderSettlement = {

    pay_type_index: 0,

    pay_type_array:{ },

    //搜索
    search: function() {

        var billType_values = $("#billType").multiselect("getChecked").map(function(){ return this.value;}).get();
        $('#bill_type').val(billType_values);
        var bill_status_values =  $("#bill_status").multiselect("getChecked").map(function(){ return this.value;}).get();
        $('#billStatus').val(bill_status_values);

        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
    },

    //重置
    clear: function(){
        document.forms['search_form'].reset();
        $('#billType').multiselect("refresh");
        $('#bill_status').multiselect("refresh");
        this.search();
    },

    timeClear: function() {
        $('#send_date').val('');
    },

    //重新加载
    load: function() {
        $("#flex").flexReload();
    },

    //订单详情
    billview: function( bill_no ) {
        window.open('/quanliadmin/app/bill/billSearch.pscript?operFlg=9&bill_no=' + bill_no);
    },

    //订单批量对账
    financialReconciliation: function(){

        financialReconciliation_array: '';

        var financialReconciliation_obj = $('#flex').find('tr.trSelected');
        if (financialReconciliation_obj.length == 0) {
            E.alert('请选择要对账的订单');
        } else {

            var temp_array = new Array();
            var error_flg = 0;

            $.each(financialReconciliation_obj, function(k, v) {
                var id = $(v).attr('id').replace('row', '');
                temp_array.push($(v).attr('id').replace('row', ''));
            });

            this.financialReconciliation_array = temp_array;
            E.confirm('您确认要对选中的订单对账吗？', 'orderSettlement.become');

        }
    },

    //订单批量对账执行
    become: function(){
        E.loadding.open('正在操作，请稍候...');
        E.ajax_post({
            url: '/invokingAjax-backend/send/financialReconciliation.ajax?operFlg=2',
            data: {
                financialReconciliation_array: this.financialReconciliation_array
            },
            call: 'orderSettlement.result'
        });
    },

    //弹出财务对账对话框
    financial: function( bill_code,bill_no ){
        this.bill_no = bill_no  ;
        E.confirm("您确认要进行对账吗？", "orderSettlement.actionConfirm");
    },

    //财务对账执行
    actionConfirm : function () {
        E.ajax_post({
            url: "/invokingAjax-backend/send/financialReconciliation.ajax?operFlg=100",
            data: {
                bill_no: orderSettlement.bill_no
            },
            call: function( obj ) {
                if (obj.code == 200) {
                    E.alert(obj.message, 2, "orderSettlement.load");
                } else {
                    E.alert(obj.message);
                }
            }
        });
    },

    //配送对账的驳回
    rejected: function(bill_code,bill_no){
        this.bill_no = bill_no  ;
        //调用打开弹出层公共JS方法
        E.popup.open({
            id:"pop1",   		 //获取id为"pop"元素内的HTML
            title: "配送对账驳回",       //弹出层标题
            css: "width:800px;",     //设置弹出层样式
            btnName: "确定驳回",         //执行“确定”操作的按钮名称
            btnCall:"orderSettlement.turnDown();"  //点击确定后执行的方法
        });
    },

    //驳回操作
    turnDown: function(){

        $("#billNo").val(this.bill_no);
        this.dt = E.getFormValues("rejected_form");
        E.loadding.open("正在驳回，请稍后...");
        E.ajax_post({
            url: "/invokingAjax-backend/send/financialReconciliation.ajax?operFlg=101",
            data: this.dt,
            call: "orderSettlement.result"
        });
    },

    //返回结果
    result: function( o ) {

        E.loadding.close();
        if (o.code == 200) {
            E.popup.close();
            E.alert(o.message, 2, 'orderSettlement.load');
        } else {
            E.alert(o.message);
        }

    },

    //点击对账按钮弹出层
    reconciliation: function( bill_code,bill_no ){

        //调用打开弹出层公共JS方法
        E.popup.open({
            id:"pop",   		 //获取id为"pop"元素内的HTML
            title: "配送对账",       //弹出层标题
            css: "width:1000px;",     //设置弹出层样式
            btnName: "完成对账",         //执行“确定”操作的按钮名称
            btnCall:"orderSettlement.check();"  //点击确定后执行的方法
        });

        //配送对账时查询订单相关数据
        E.ajax_get({
            url: '/invokingAjax-backend/send/orderSettlement.ajax?operFlg=5',
            data: {
                bill_no: bill_no
            },
            call: function( obj ) {

                if(obj.code == 200){
                    $('#billCode').val(bill_code);
                    $('#bill_no').val(bill_no);
                    $('#billTotalMoney').val(obj.data.bill_money);
                    $('#billPaidAmount').val(obj.data.bill_received_money);
                    $('#billUnpaidAmount').val(obj.data.bill_receivable_money);
                    $('#deliveries').val(obj.data.distribution_technicia);
                    if(obj.data.bill_reject_cause){
                        var html1="";
                        html1 +='<tr><td><span>驳回原因：'+obj.data.bill_reject_cause+'<span><td><tr>';
                        $('#rejectCause').append(html1);
                    }
                    $('#reject_cause').val();
                    var html = "";
                    $.each(obj.data.pay_data, function(i,p){
                        if(p.type == 6){
                            html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                            html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                            html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                            html += ' <tr><td>'+ p.payTypeName +'</td>';
                            html += '<td>'+obj.data.bill_coupon_money+'</td>';
                            html += '<td>'+obj.data.bill_coupon_money+'</td>';
                            html += '<td>0</td>';
                            html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td></td>';
                            html += '<td><input type="hidden" name="pay_type[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                            html += '<td></td></tr>';
                        }
                        if(p.type == 4){
                            html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                            html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                            html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                            html += ' <tr><td>'+ p.payTypeName +'</td>';
                            html += '<td>'+p.pay_amount+'</td>';
                            html += '<td>'+p.pay_amount+'</td>';
                            html += '<td>0</td>';
                            html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td></td>';
                            html += '<td><input type="hidden" name="pay_type[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                            html += '<td></td></tr>';
                        }
                        if(p.type == 5){
                            html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                            html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                            html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                            html += ' <tr><td>'+ p.payTypeName +'</td>';
                            html += '<td>'+p.pay_amount+'</td>';
                            html += '<td>'+p.pay_amount+'</td>';
                            html += '<td>0</td>';
                            html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td></td>';
                            html += '<td><input type="hidden" name="pay_type[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                            html += '<td></td></tr>';
                        }
                        if(p.type == 2){
                            html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                            html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                            html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                            html += ' <tr><td>'+p.payTypeName +'</td>';
                            html += '<td>'+ p.pay_amount+'</td>';
                            html += '<td>'+ obj.data.bill_online_money +'</td>';
                            html += '<td>'+ p.pay_online_amount +'</td>';
                            html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /></td>';
                            html += '<td><input type="hidden" name="pay_type[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                            html += '<td></td></tr>';
                        }
                        if(p.type == 7){
                            html += '<input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" />';
                            html += '<input type="hidden" name="type[]" value="'+ p.type +'" />';
                            html += '<input type="hidden" name="pay_ment[]" value="'+ p.payTypeName +'" />';
                            html += ' <tr class="pay_type_line"><td>'+ p.payTypeName +'</td>';
                            html += '<td>'+p.pay_amount+'</td>';
                            html += '<td>'+p.pay_amount+'</td>';
                            html += '<td>0<input type="hidden" name="pay_type[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control"  name="posCut[]" value="" /></td>';
                            html += '<td><input type="text" class="form-control" style="height:28px;" id="casCardNumber" name="casCardNumber" value="" /></td>';
                            html += '<td><input type="hidden" class="form-control" name="get_money[]" value="" /></td>';
                            html += '<td></td></tr>';
                        }
                        if(p.type == 1){
                            if(p.payment_method_type == 1){
                                html += ' <tr class="pay_type_line"><td>'+p.payment_method_name+'</td>';
                                html += '<td>'+obj.data.bill_receivable_money+'</td>';
                                html += '<td>0<input type="hidden" name="pay_type[]" value="" /></td>';
                                html += '<td>'+obj.data.bill_receivable_money+'</td>';
                                html += '<td><input type="hidden" class="form-control" name="posSerialNumber[]" value="" /><input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" /></td>';
                                html += '<td><input type="hidden" class="form-control" name="posCut[]" value="" /><input type="hidden" name="type[]" value="'+ p.payment_method_id +'" /></td>';
                                html += '<td><input type="hidden" name="pay_ment[]" value="' + p.payment_method_name +'" /></td>';
                                html += '<td><input type="text" class="form-control" style="width:80px;height:28px;" name="get_money[]" value="" /></td>';
                                html += '<td id="new_'+orderSettlement.pay_type_index+'"><span style="border: 1px; border-radius: 4px; width: 70px; height: 30px; padding: 6px 9px; background:#3071a9;"><a  href="javascript: void(0);"onclick="orderSettlement.removeTable('+orderSettlement.pay_type_index+');"><font style="color:#fff">删除</font></a></span></td></tr>';
                            }else{
                                html += ' <tr class="pay_type_line"><td>' + p.payment_method_name +'</td>';
                                html += '<td>'+obj.data.bill_receivable_money +'</td>';
                                html += '<td>0<input type="hidden" name="pay_type[]" value="" /></td>';
                                html += '<td>'+ obj.data.bill_receivable_money +'</td>';
                                html += '<td><input type="text" class="form-control" style="width:100px;height:28px;" name="posSerialNumber[]" value="" /><input type="hidden" name="billPayNo[]" value="'+ p.bill_pay_no +'" /></td>';
                                html += '<td><input type="text" class="form-control" style="width:100px;height:28px;" name="posCut[]" value="" /><input type="hidden" name="type[]" value="'+ p.payment_method_id +'" /></td>';
                                html += '<td><input type="hidden" name="pay_ment[]" value="' + p.payment_method_name +'" /></td>';
                                html += '<td><input type="text" class="form-control" style="width:80px;height:28px;" name="get_money[]" value="" /></td>';
                                html += '<td id="new_'+orderSettlement.pay_type_index+'"><span style="border: 1px; border-radius: 4px; width: 70px; height: 30px; padding: 6px 9px; background:#3071a9;"><a  href="javascript: void(0);"onclick="orderSettlement.removeTable('+orderSettlement.pay_type_index+');"><font style="color:#fff">删除</font></a></span></td></tr>';
                            }
                        }
                    });
                    $('#billPay').html(html);
                }
            }
        });
    },

    //对账操作
    check: function(){
        dt: "",
        this.dt = E.getFormValues("reconciliationForm");

        E.loadding.open("正在对账，请稍后...");
        E.ajax_post({
            url: '/invokingAjax-backend/send/orderSettlement.ajax?operFlg=100',
            data:this.dt,
            call: "orderSettlement.result"
        });
    },

    //点击新增对账支付方式
    addTable: function(){

        //配送方式条数索引加1
        orderSettlement.pay_type_index++;

        var type = $("#changePayment").val();

        var pay_type = $('#changePayment').find("option:selected").attr("flg");
        var pay_ment = $('#changePayment').find("option:selected").text();
        html = "";
        html += ' <tr class="pay_type_line"><td>'+pay_ment+'</td>';
        html += '<td><input type="hidden" name="type[]" value="'+type+'" /></td>';
        html += '<td><input type="hidden" name="pay_ment[]" value="'+pay_ment+'" /></td>';
        html += '<td><input type="hidden" name="billPayNo[]" value="" /></td>';
        if(pay_type == 1){
            html += '<td><input type="hidden" class="form-control" style="width:100px;height:28px;" name="posSerialNumber[]" value="" /></td>';
            html += '<td><input type="hidden" class="form-control" style="width:100px;height:28px;" name="posCut[]" value="" /></td>';
        }else{
            html += '<td><input type="text" class="form-control" style="width:100px;height:28px;" name="posSerialNumber[]" value="" /></td>';
            html += '<td><input type="text" class="form-control" style="width:100px;height:28px;" name="posCut[]" value="" /></td>';
        }
        html += '<td><input type="hidden" name="pay_type[]" value="'+pay_type+'" /></td>';
        html += '<td><input type="text" class="form-control" style="width:80px;height:28px;" name="get_money[]" value="" /></td>';
        html += '<td id="new_'+orderSettlement.pay_type_index+'"><span style="border: 1px; border-radius: 4px; width: 70px; height: 30px; padding: 6px 9px; background:#3071a9;"><a  href="javascript: void(0);"onclick="orderSettlement.removeTable('+orderSettlement.pay_type_index+');"><font style="color:#fff">删除</font></a></span></td></tr>';

        $('#payTbody').append(html);
        $('#addPayTable').css('display','block');
    },

    //点击删除新增对账支付方式
    removeTable: function(i){
        $('#new_'+i).parent().remove();
//            $('#addPayTable').css('display','none');
    }

}

$(window).ready(function() {

    $("#deliver_cityid").html("");

    var cityHtml = '<option value="">请选择</option>';

    $.ajax({
        type: "post",
        url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
        dataType: "json",
        data: "",
        success: function( result_obj ) {
            if(result_obj.code == 200){
                var selected = "";
                if(result_obj.data.length == 1){
                    selected = "selected";
                }
                $.each(result_obj.data, function(i,val){
                    cityHtml +='<option value="'+val.id+'" '+selected+'>'+val.name+'</option>';
                });
                $('#deliver_cityid').html(cityHtml);
                $("#deliver_cityid").trigger("change");
            }else{
                E.alert(result_obj.message);
            }
        }
    });


    //点击城市联动获得配送站
    $(document).on('change', '#deliver_cityid', function() {

        $('#distribution_id').html("");
        $('#distribution_technician_id').html('');

        var deliver_cityid = $('#deliver_cityid').children('option:selected').val();
        var distributionHtml = '<option value="">请选择</option>';
        var technicianHtml = '<option value="">请选择</option>';
        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
            dataType: "json",
            data: {deliver_cityid: deliver_cityid},
            success: function( obj ) {
                if(obj.code ==200 && obj.data != null){
                    var selected = "";
                    if(obj.data.length == 1){
                        selected = "selected";
                    }
                    $.each(obj.data, function(i,val){
                        distributionHtml +='<option value="'+val.distribution_id+'" '+selected+'>'+val.distribution_name+'</option>';
                    });
                    $('#distribution_id').html(distributionHtml);
                    $('#distribution_technician_id').html(technicianHtml);
                }else{
                    distributionHtml += '';
                    $('#distribution_id').html(distributionHtml);
                    $('#distribution_technician_id').html(technicianHtml);
                }
                $("#distribution_id").trigger("change");
            }
        });
    });
//城市，配送站，配送员联动
    $(document).on('change', '#distribution_id', function() {

        $('#distribution_technician_id').html('');
        var distribution_id = $('#distribution_id').children('option:selected').val();
        var technicianHtml = '<option value="">请选择</option>';
        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=3",
            dataType: "json",
            data: {distribution_id: distribution_id},
            success: function( o ) {
                if(o.code ==200 && o.data != null){
                    $.each(o.data, function(i,val){
                        technicianHtml +='<option value="'+val.distribution_technician_id+'">'+val.distribution_technician_name+'</option>';
                    });
                    $('#distribution_technician_id').html(technicianHtml);
                }else{
                    technicianHtml += '';
                    $('#distribution_technician_id').html(technicianHtml);
                }
            }
        });
    });


});




</script>

</body>

</html>
